<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    let loginList = [
      { userName: 'admin', password: 'admin321' },
      { userName: 'zhangsan', password: 'zs321' },
      { userName: 'lisi', password: 'ls321' },
      { userName: 'yyqx', password: 'yyqx321' }
    ]

    // 现有的用户信息列表
    // 根据生成的token 去掉找到 对应的信息
    let userInfo = {
      token1: {
        city: '杭州',
        money: '1000w',
        sex: '女',
        userName: 'admin',
        password: 'admin321'
      },
      token2: {
        city: '北京',
        money: '1100w',
        sex: '女',
        userName: 'zhangsan',
        password: 'zs321'
      },
      token3: {
        city: '北京',
        money: '800w',
        sex: '男',
        userName: 'lisi',
        password: 'ls321'
      },
      token4: {
        city: '天津',
        money: '600w',
        sex: '男',
        userName: 'yyqx',
        password: 'yyqx321'
      }
    }
    function fu() {
      let count = 2
      for (; ;) {
        let naw = prompt('请输入你的用户名')
        let dnv = prompt('请输入你的用户密码')
        let token = 'token' + Math.floor(Math.random() * (4) + 1)

        for (let i = 0; i < loginList.length; i++) {
          if (loginList[i].userName === naw && loginList[i].password === dnv) {
            return alert(`登入成功，具体用户信息
          city:${userInfo[token].city}
          money:${userInfo[token].money}:
          sex::${userInfo[token].sex}
          userName:${userInfo[token].userName}`)
          }

        }
        count--
        if (count === 0) return alert('用户密码错误，你没机会了耶！！！！')


        function fa() {

          let maj = +prompt(`用户密码错误
          1.注册
          2.退出`)

          if (maj === 1) {
            let nav = prompt(`请输入你的注册用户名`)
            let nas = prompt(`请输入你的注册密码`)
            loginList.push({ userName: nav, password: nas })

            return
          }
          if (maj === 2) {
            return
          }


        }
        fa()


      }
    }
    fu()
  </script>
</body>

</html>